{% extends 'base-layer.html' %}
{% load staticfiles %}

{% block css %}
<link rel="stylesheet" href="{% static 'js/plugins/layer/skin/layer.css' %}">
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap-datetimepicker.min.css' %}">
<link rel="stylesheet" href="{%static 'plugins/select2/select2.min.css' %}">
<style>
    textarea{
        height: 400px;
        width: 568px;
    }
</style>
{% endblock %}

{% block main %}
<div class="box box-danger">
	<form class="form-horizontal" id="addForm" method="post" autocomplete="off">
		{% csrf_token %}
		<input type="hidden" name='id' value="{{ structure.id }}" />
		<div class="box-body">
          <fieldset>
            <legend>
              <h4>公告信息</h4>
            </legend>
            <div class="form-group has-feedback">
                <label class="col-sm-4 control-label">标题</label>
                <div class="col-sm-4">
                    <input class="form-control" name="title" type="text" value="{{ structure.title }}"/>
                </div>
            </div>
            <div class="form-group has-feedback">
                <label class="col-sm-4 control-label">分类</label>
                <div class="col-sm-4">
                  <select class="form-control select2" name="category">
                    <option value="{{ structure.category_id }}">{{ structure.category }}</option>
                    {% for s in categorys %}
                        <option value="{{ s.c_id }}">{{s.name}}</option>
                    {% endfor %}
                  </select>
                </div>
            </div>
{#            <div class="form-group has-feedback">#}
{#                <label class="col-sm-4 control-label">可见范围</label>#}
{#                <div class="col-sm-4">#}
{#                    <select class="form-control select2" name="users" >#}
{#                    <option value="{{ p_user.id }}">{{ p_user.name }}</option>#}
{#                    {% for u in users %}#}
{#                        <option value="{{ u.id }}">{{ u.name }}</option>#}
{#                    {% endfor %}#}
{#                    </select>#}
{#                    <label class="control-label">#}
{#                      <input type="radio" class="minimal" name="isopen"  value="True" {% ifequal batch.isopen True %}checked{% endifequal %}{% if not batch.isopen %}checked{% endif %}>所有人员#}
{#                    </label>#}
{#                    <label class="control-label">#}
{#                      <input type="radio" class="minimal" name="isopen"  value="False" {% ifequal batch.isopen False %}checked{% endifequal %}>指定范围#}
{#                    </label>#}
{#                    <label class="control-label">#}
{#                      <a href="#" onclick="visible()">设定范围</a>#}
{#                    </label>#}
{#                </div>#}
{#            </div>#}
            <div class="form-group has-feedback">
                <label class="col-sm-4 control-label">发布时间</label>
                <div class="col-sm-4">
                    <input class="form-control form_datetime" name="pubdate" type="text" value="{{ structure.pubdate |date:'Y-m-d H:m:s' }}"/>
                </div>
            </div>
            <div class="form-group has-feedback">
                <label class="col-sm-4 control-label">正文</label>
                <div class="col-sm-4">
                    <textarea id="content" name="content">{{ structure.content }}</textarea>
                </div>
            </div>
          </fieldset>

		</div>
		<div class="box-footer ">
			<div class="row span7 text-center ">
              <button type="button" id="btnCancel" class="btn btn-default margin-right " >重置</button>
              <button type="button" id="btnSave" class="btn btn-info margin-right " >保存</button>
			</div>
		</div>

	</form>
</div>

{% endblock %}

{% block javascripts %}
<script src="{% static 'plugins/select2/select2.full.min.js' %}"></script>
<script src="{% static 'bootstrap/js/bootstrap-datetimepicker.js' %}"></script>
<script src="{% static 'ckeditor/ckeditor/ckeditor.js' %}"></script>
<script type="text/javascript">

	$("#btnSave").click(function(){
		var data = $("#addForm").serialize();
        var oEditor = CKEDITOR.instances.content;
        var a = oEditor.getData();
        data=data.split('content=')[0]+'content='+a;
        console.log(data);
		$.ajax({
			type: $("#addForm").attr('method'),
			url : "{% url 'news_add' %}",
			data : data,
			cache: false,
			success : function(msg) {
				if (msg.result){
					layer.alert('数据保存成功！', {icon: 1},function(index){
					    parent.layer.closeAll(); //关闭所有弹窗
                    });
				}else{
					layer.alert('数据保存失败', {icon: 5});
                    //$('errorMessage').html(msg.message)
				}
				return ;
			}
		});
	});

    /*input 时间输入选择*/
    $(".form_datetime").datetimepicker({
            language:  'zh',
            minView: 0, //选择范围知道日期，不选择时分
            {#weekStart: 1,#}
            {#todayBtn:  1,#}
            autoclose: 1,
            todayHighlight: 1,
            //startView: 0,
            forceParse: 0,
            showMeridian: 1,
            format: 'yyyy-mm-dd hh:ii:ss'
        }).on('changeDate', function (ev) {
            $(this).datetimepicker('hide');
    });

	/*点取消刷新新页面*/
    $("#btnCancel").click(function () {
	    window.location.reload();
    });

    CKEDITOR.replace( 'content', {
        uiColor: '#c0c0c0',
        height:150,
        toolbar:[
                ['Bold','Italic','Underline','Strike','Subscript','Superscript'],
                ['NumberedList','BulletedList','-','Outdent','Indent'],
                ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
                ['Link','Unlink','Anchor'],
                ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
                '/',
                ['Styles','Format','Font','FontSize'],
                ['TextColor','BGColor'],
                ['Maximize', 'ShowBlocks','-']
                ]
    });



</script>

{% endblock %}
